
dim fso, file
Dim FileName, FileContents

Dim files(1)


Wscript.Echo "Starting standalone_to_blocks"


files(0) = "C:\Websites\Production Websites\Dev\FCChat\svn\trunk\dev\js\fcchat.moderation.min.js"
files(1) = "C:\Websites\Production Websites\Dev\FCChat\svn\trunk\dev\js\fcchat.standalone.min.js"

block = "C:\Websites\Production Websites\Dev\FCChat\svn\trunk\dev\js\"

For Each file in files

newfile = file & ".aspx"

FileContents = GetFile(file)
	
importfile=""	
filepos=1
blockpos=0
count=0
do while true
	blockpos=InStr(filepos,FileContents,"/* @INLINE FILE")
	if(blockpos<>0) then
		if(blockpos>filepos) then
			importfile= importfile & Mid(FileContents,filepos,blockpos-filepos)
		end if
		filename=Mid(FileContents,blockpos+16,InStr(blockpos+16,FileContents," ")-(blockpos+16))
		Wscript.Echo filename
		endblockpos=InStr(blockpos,FileContents,"@END FILE*/")
		if(endblockpos<>0) then
			endheaderpos=InStr(blockpos,FileContents,"*/")
			header = "<!--#include file='" & filename & "' -->" & vbcrlf & vbcrlf & vbtab
			header = header & Mid(FileContents,blockpos,endheaderpos-blockpos+2)
			fileblock=Mid(FileContents,blockpos,endblockpos-blockpos+11)
			WriteFile block & filename, fileblock
			count = count + 1

			importfile = importfile & header
			filepos = endblockpos + 11
		else
				Wscript.Echo "an error has occurred"
				Wscript.quit
		end if
	else
		importfile = importfile & Mid(FileContents,filepos)
		WriteFile newfile, importfile
		exit do
	end if

loop
next

	
Wscript.Echo "done"
Wscript.quit

'///////////////////////////////
' FUNCTIONS
'///////////////////////////////

Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
' Written by Rob van der Woude
' http://www.robvanderwoude.com
    ' Check if the script runs in CSCRIPT.EXE
    If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
        ' If so, use StdIn and StdOut
        WScript.StdOut.Write myPrompt & " "
        UserInput = WScript.StdIn.ReadLine
    Else
        ' If not, use InputBox( )
        UserInput = InputBox( myPrompt )
    End If
End Function

Sub commit(f)
	return = WshShell.Run("C:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:commit /path:""" + f + """ /logmsg:""daily"" /closeonend:1",1,true)
End sub

'Read text file
function GetFile(FileName)
  If FileName<>"" Then
    Dim FS, FileStream
    Set FS = CreateObject("Scripting.FileSystemObject")
      on error resume Next
      Set FileStream = FS.OpenTextFile(FileName)
      GetFile = FileStream.ReadAll
    if Err.number <> 0 then
	Wscript.Echo "error reading file" + Filename
    end if
  End If
End Function

'Write string As a text file.
function WriteFile(FileName, Contents)
  Dim OutStream, FS

  on error resume Next
  Set FS = CreateObject("Scripting.FileSystemObject")
    Set OutStream = FS.OpenTextFile(FileName, 2, True)
    OutStream.Write Contents
    if Err.number <> 0 then
	Wscript.Echo "error writing file" + FileName & Err.number
    else
	Wscript.Echo "Replace done on " + FileName
        fileswritten = fileswritten + 1
    End if
End Function
